package com.cmpe451.nutty.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.cmpe451.nutty.dao.TwitterDao;
import com.cmpe451.nutty.model.Follow;
import com.cmpe451.nutty.model.User;
import com.cmpe451.nutty.model.Tweet;
import com.cmpe451.nutty.utils.MyLogger;

@Component
public class TestServiceImpl implements TestService, InitializingBean {

	private MyLogger logger = MyLogger.getLogger(getClass());

	@Autowired
	private TwitterDao twitterDao;

	@Override
	public void afterPropertiesSet() throws Exception {

	}

//	@Override
//	@Scheduled(cron = "0 * * * * ?")
//	public void runClockTask() {
//		logger.info("runClockTask::SYSTEM CLOCK IS {0}", new Date());
//	}

	@Override
	public int getTwitterUsersCount() {
		return twitterDao.findTwitterUsersCount();
	}

	@Async
	@Override
	public void insertTweetAsync(Tweet tweet) {
	}
	
	@Override
	public void saveFollow(Follow follow) {
		twitterDao.save(follow);
	}	

	@Override
	public void saveModel(User model) {
		twitterDao.save(model);
	}

	@Override
	public List<User> getUsers() {
		return twitterDao.findAll(User.class);
	}

	@Override
	public List<Follow> getFollowers(String username) {
		// TODO Auto-generated method stub
		return twitterDao.findFollowedOnes(username);
	}

	@Override
	public List<Follow> getFollowings(String username) {
		// TODO Auto-generated method stub
		return twitterDao.findFollowingOnes(username);
	}

	@Override
	public void deleteFollow(Follow follow) {
		// TODO Auto-generated method stub
		twitterDao.delete(follow);
	}

	@Override
	public Follow findFollowship(String currentUsername, String username) {
		// TODO Auto-generated method stub
		return twitterDao.findFollowshipByUsernames(currentUsername, username);
	}

}
